package fr.auzaiphe.titleScreen;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SpringLayout;

/**
 * Interface graphique de l'�cran titre
 * @author Jojo
 *
 */
public class AccueilPanel extends JPanel
{
	private TitleScreen titleScreen;

	private SpringLayout layout;
	private JButton btnJoueur;
	private JButton btnAdmin;
	private JLabel labelIP;
	private JTextField fieldIP;

	public AccueilPanel( TitleScreen pTitleScreen )
	{
		super();
		this.titleScreen = pTitleScreen;

		this.layout = new SpringLayout();
		this.setLayout( this.layout );

		/* Bouton Joueur */
		this.btnJoueur = new JButton("Connexion en tant que joueur");
		this.layout.putConstraint(SpringLayout.WEST, this.btnJoueur, 250, SpringLayout.WEST, this );
		this.layout.putConstraint(SpringLayout.EAST, this.btnJoueur, -250, SpringLayout.EAST, this );
		this.layout.putConstraint(SpringLayout.NORTH, this.btnJoueur, 105, SpringLayout.NORTH, this );
		this.layout.putConstraint(SpringLayout.SOUTH, this.btnJoueur, 50, SpringLayout.NORTH, this.btnJoueur );
		this.btnJoueur.addActionListener( new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{
				AccueilPanel.this.titleScreen.initJoueur( AccueilPanel.this.fieldIP.getText() );
			}
		});
		this.add(this.btnJoueur);

		/* Label adresse IP */
		this.labelIP = new JLabel();
		this.layout.putConstraint(SpringLayout.WEST, this.labelIP, 0, SpringLayout.WEST, this.btnJoueur );
		this.layout.putConstraint(SpringLayout.NORTH, this.labelIP, 20, SpringLayout.SOUTH, this.btnJoueur );
		this.labelIP.setText("IP du serveur :");
		this.add(this.labelIP);

		/* Champ texte adresse IP */
		this.fieldIP = new JTextField();
		this.layout.putConstraint(SpringLayout.NORTH, this.fieldIP, 5, SpringLayout.SOUTH, this.labelIP );
		this.layout.putConstraint(SpringLayout.WEST, this.fieldIP, 0, SpringLayout.WEST, this.labelIP );
		this.layout.putConstraint(SpringLayout.EAST, this.fieldIP, 0, SpringLayout.EAST, this.btnJoueur );
		this.layout.putConstraint(SpringLayout.SOUTH, this.fieldIP, 25, SpringLayout.NORTH, this.fieldIP );
		this.add(this.fieldIP);

		/* Bouton Admin */
		this.btnAdmin = new JButton("Connexion en tant qu'admin");
		this.layout.putConstraint(SpringLayout.WEST, this.btnAdmin, 0, SpringLayout.WEST, this.btnJoueur );
		this.layout.putConstraint(SpringLayout.EAST, this.btnAdmin, 0, SpringLayout.EAST, this.btnJoueur );
		this.layout.putConstraint(SpringLayout.NORTH, this.btnAdmin, 60, SpringLayout.SOUTH, this.fieldIP );
		this.layout.putConstraint(SpringLayout.SOUTH, this.btnAdmin, 50, SpringLayout.NORTH, this.btnAdmin );
		this.btnAdmin.addActionListener( new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{
				AccueilPanel.this.titleScreen.initAdmin();
			}
		});
		this.add(this.btnAdmin);
	}
}